//main.cpp 主函数
/*Designed by Zhenghua Ma, Department of Mechanical Engineering of THU, 2819538005@qq.com*/
#include"calculator.cpp"
#include<string>
#include<Windows.h>//支持调用系统时间的API
#include<time.h>//支持获取clock_t统计软件工作时间
using namespace std;

int main()
{
	clock_t start, finish;
	start = clock();
	Calculator<double> myCalculator;
	SYSTEMTIME myTime;
	GetLocalTime(&myTime);
	ofstream log;
	log.open("calculatorLog.txt", ios_base::in | ios_base::app);
	log << myTime.wYear << '/' << myTime.wMonth << '/' << myTime.wDay << ' ' << myTime.wHour << ':' <<
		myTime.wMinute << ' ';//作为日志，记录运行的状态
	char mode;
	while (1) {
		cout << "请问您要以正常计算还是测试模式启动本软件？正常模式请输入N，测试模式请输入T，输入完请回车：";
		cin >> mode;
		if (mode == 'T' || mode == 't' || mode == 'n' || mode == 'N')
			break;
		cout << "您的输入有误，请重新输入！\n";
	}
	if (mode == 'T' || mode == 't') {
		log << "以测试模式运行 ";
		cout << "//********进入测试模式********//\n" << "请输入测试文件路径（例如C:\\Users\\test.txt）：\n";
		string filePath;
		cin >> filePath;
		ifstream file(filePath);
		while (!file.is_open()) {
			cout << "文件路径错误，请重新输入文件路径！\n";
			cin >> filePath;
			file.open(filePath);
		}
		myCalculator.centralCalculator(file);
	}
	else {
		log << "以正常模式运行 ";
		myCalculator.centralCalculator(cin);
	}
	finish = clock();
	log << "正常退出 运行时间为" << (double)(finish - start) / CLOCKS_PER_SEC << "秒\r";
	system("pause");
	return 0;
}